﻿using System;
using System.Collections.Generic;

namespace Microsoft.WowAddonStudio.TocEditor
{
	/// <summary>
	/// Represents metadata entries in a TOC file.
	/// </summary>
	public class TocMetadata
	{
		#region Private members

		private readonly Dictionary<string, string> metadataEntries = new Dictionary<string, string>();

		#endregion

		#region Public methods and properties

		/// <summary>
		/// Checks whether the metadata entries contain an entry with the given key.
		/// </summary>
		public bool ContainsKey(string key)
		{
			return metadataEntries.ContainsKey(key);
		}

		/// <summary>
		/// Indexer for accessing values based on TOC tag names.
		/// </summary>
		/// <param name="name">Name of tag whose value should be retrieved or set.</param>
		/// <returns>Value belonging to given tag or null, if tag is not present.</returns>
		public string this[string name]
		{
			get { return metadataEntries[name]; }
			set
			{
				if (name == null)
					throw new ArgumentNullException("name");

				metadataEntries[name] = value;
			}
		}

		/// <summary>
		/// Removes an entry.
		/// </summary>
		/// <param name="key">Key which should be removed.</param>
		public void Remove(string key)
		{
			metadataEntries.Remove(key);
		}

		/// <summary>
		/// Empties the metadata container.
		/// </summary>
		public void Clear()
		{
			metadataEntries.Clear();
		}

		/// <summary>
		/// Gets the content of the container.
		/// </summary>
		public IEnumerable<KeyValuePair<string, string>> GetTags()
		{
			foreach (var pair in metadataEntries)
			{
				yield return pair;
			}
		}

		#endregion
	}
}